# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/28 21:35
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : otsu_seg.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
import cv2 as cv
from DIP_experiment_5.util import contrast_show

im_path = "../experiment_fig/brain.tif"
font_path = "C:/Windows/Fonts/simhei.ttf"
im = cv.imread(im_path)
b, g, r = cv.split(im)
retval, dst = cv.threshold(r, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
im_dict = {"原始图像r通道": r, "OTSU分割r通道": dst}
print(f"全局最佳阈值为{retval}")
contrast_show(im_dict, (1, 2), font=font_path)
